﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PPI.Client.Logic;
using PPI.Client.Presenter;
using PPI.Client.Utils;
using PPI.Entities.Settings.Mobile;

namespace PPI
{
    public partial class frmDownloadProjectDatabase : frmBase, IDownloadProjectDatabase
    {
        private bool m_IsDownloadingDatabase;
        private DownloadProjectDatabasePresenter m_Presenter;


        public frmDownloadProjectDatabase()
        {
            InitializeComponent();
            base.MenuMain.Visible = false;
            this.FormSize = FormSizes.Medium;

        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnView_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void frmDownloadProjectDatabase_Load(object sender, EventArgs e)
        {

            try
            {
                m_Presenter = new DownloadProjectDatabasePresenter(this);
                Application.DoEvents();
                if (this.OnLoad != null)
                {
                    this.OnLoad(this, new EventArgs());
                }
            }
            catch (Exception ex)
            {
                RegisterError.SaveError(ex);
            }
        }

        private void frmDownloadProjectDatabase_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (m_IsDownloadingDatabase)
                e.Cancel = true;
        }

        private void btnDownload_Click(object sender, EventArgs e)
        {
            try
            {
                m_Presenter.StartDownload();
            }
            catch (Exception ex)
            {
                RegisterError.SaveError(ex);
            }
        }


        #region IDownloadProjectDatabase

        public int ProgressDownload
        {
            set { pbDownload.Value = value; }
        }

        public string MessageDownloading
        {
            set { lblDownload.Text = value; }
        }

        public string MessageLastUpdate
        {
            set { lblLastUpdate.Text = value; }
        }

        public string MessageToDownload
        {
            set { btnDownload.Text = value; }
        }

        public bool IsDownloading
        {
            set { m_IsDownloadingDatabase = value; }
        }

        public event EventHandler<EventArgs> OnLoad;

        public void ShowError(string message)
        {
            MessageBox.Show(message);
        }

        public void ChangeProgressStyleToMarquee()
        {
            pbDownload.ProgressType = DevComponents.DotNetBar.eProgressItemType.Marquee;
        }

        public void ChangeProgressStyleToSteps()
        {
            pbDownload.ProgressType = DevComponents.DotNetBar.eProgressItemType.Standard;
        }

        #endregion
    }
}
